package com.vtest.mes.service.impl;

import com.vtest.mes.mapper.MesMapper;
import com.vtest.mes.service.MesService;
import com.vtest.mes.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @program: MesHelper
 * @author: tiger
 * @create: 2024-12-11 17:38
 * @Description : 处理mes数据的service层
 */

public class MesServiceImpl implements MesService {

    @Autowired
    private MesMapper mesMapper;

    /**
     * @return java.lang.String
     * @Description: 获取最新可用的TrackNum
     * @Date 2024/12/11 17:59
     * @Param [partTrackNum]
     */
    @Override
    public String getLatestTrackNum(String partTrackNum) {
        int lineNum = 1;
        List<String> trackNumList = mesMapper.getTrackNumByPart(partTrackNum);
        if (trackNumList.size() == 0) return partTrackNum + "01";  //没有查到数据的话 就返回 partTrackNum +01
        String newTrackNum = trackNumList.get(0);
        lineNum = Integer.parseInt(newTrackNum.substring(11)) + 1;  //获取新的后缀

        //填充后缀 并 拼接成 trackNum
        String trackNum = partTrackNum + StringUtils.autoFillFrontStr(lineNum + "", 2, "0");

        return trackNum;
    }
}
